<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Insert title here</title>
        <jsp:include page="/view/taglib.jsp"></jsp:include>
    </head>
    <body>
        <div class="easyui-layout" data-options="fit:true">
            <div data-options="region:'north',split:true,border:false" style="height:80px;">
                <form id="searchForm">
                    <table>
                        <tr>
                            <td><a id="btn_add" class="easyui-linkbutton" data-options="group:'g1',iconCls:'icon-add'">添加</a></td>
                            <td><a id="btn_dele" class="easyui-linkbutton" data-options="group:'g1',iconCls:'icon-remove'">删除</a></td>
                            <td><a onclick="grid.datagrid('reload');" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-arrow_refresh'">刷新</a></td>
                        </tr>
                    </table>
                    <table>
                        <tr>
                            <td>用户名称</td>
                            <td><input name="user_nameSch" class="textbox" style="width: 120px; height: 22px;" /></td>
                            <td>创建时间</td>
                            <td><input name="createdStartSch" class="easyui-datebox" style="width: 100px" />
                                -
                                <input name="createdEndSch" class="easyui-datebox" style="width: 100px" />
                            </td>
                            <td><a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom',plain:true" onclick="grid.datagrid('load',fw.serializeObject($('#searchForm')));">过滤</a> <a href="javascript:void(0);" id="reset_searchFilter" class="easyui-linkbutton" data-options="iconCls:'ext-icon-zoom_out',plain:true" onclick="$('#searchForm input').val('');grid.datagrid('load',{});">重置过滤</a></td>
                        </tr>
                    </table>
                </form>
            </div>
            <div data-options="region:'center',border:false">
                <table id="grid">
                </table>
            </div>
            <div data-options="region:'east',split:true,border:false" style="width: 50%; padding: 5px;">
                <form id="form" name="form" method="post" class="form">
                    <fieldset>
                        <legend> 基本信息--<span id="operateMode_title">添加模式</span> </legend>
                        <table class="table">
                            <tbody>
                            	<tr style="display:none;">
                                    <th>id</th>
                                    <td><input id="id" name="id" class="textbox"      style="height: 22px;" /></td>
                                </tr>
							    <tr>
                                    <th>表单编号</th>
                                    <td><input id="number" name="number" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>创建人</th>
                                    <td><input id="founder" name="founder" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>合同名称</th>
                                    <td><input id="contractName" name="contractName" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>合同编号</th>
                                    <td><input id="contractNum" name="contractNum" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>签订日期</th>
                                    <td><input id="signTime" name="signTime" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>合同金额</th>
                                    <td><input id="account" name="account" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>负责人姓名</th>
                                    <td><input id="responsibleName" name="responsibleName" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>负责人电话</th>
                                    <td><input id="responsiblePhone" name="responsiblePhone" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>客户</th>
                                    <td><input id="customerId" name="customerId" class="textbox"   required="true"    style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>受理类型</th>
                                    <td><input id="accpetType" name="accpetType" class="textbox"  required="true"     style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>错误类型</th>
                                    <td><input id="faultCategory" name="faultCategory" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>计划到达时间</th>
                                    <td><input id="planArriveTime" name="planArriveTime"  class="easyui-datetimebox"  style="width: 180px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>计划结束时间</th>
                                    <td><input id="planFinishTime" name="planFinishTime"  class="easyui-datetimebox"  style="width: 180px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>任务类型</th>
                                    <td><input id="taskType" name="taskType" class="textbox"   required="true"    style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>工程师</th>
                                    <td><input id="engineer" name="engineer" class="textbox"  required="true"     style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>交通方式</th>
                                    <td><input id="transportation" name="transportation" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>联系人</th>
                                    <td><input id="contactName" name="contactName" class="textbox"  required="true"     style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>职务</th>
                                    <td><input id="contactPosition" name="contactPosition" class="textbox"  required="true"     style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>联系人电话</th>
                                    <td><input id="contactPhone" name="contactPhone" class="textbox"   required="true"    style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>固定电话</th>
                                    <td><input id="fixedPhone" name="fixedPhone" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>收费标准</th>
                                    <td><input id="charge" name="charge" class="textbox"  required="true"     style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>标准工时</th>
                                    <td><input id="workHours" name="workHours" class="textbox"   required="true"    style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>派单要求</th>
                                    <td colspan="3"><textarea id="sendDemand" name="sendDemand" style="width: 98%; margin-bottom: 3px;"></textarea>
                                       <!-- <input type="button" mode="0" class="editor" onclick="EditorRender('sendDemand',$(this))" value="切换至编辑器" />-->
                                    </td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>故障原因</th>
                                    <td><input id="issueReason" name="issueReason" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>状态</th>
                                    <td><input id="status" name="status" class="textbox"      style="height: 22px;" /></td>
                                </tr>
                                
                                                                                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>定时发布</th>
                                    <td><input id="releaseTime" name="releaseTime"  class="easyui-datetimebox"  style="width: 180px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>循环发布</th>
                                    <td>  <br>循环次数： <input id="loopTime" value="0" name="loopTime" class="textbox"   style="height: 22px;width: 90px;" />次
                                    	 <br> <br>循环周期： <input id="loopPeriod" value="0" name="loopPeriod" class="textbox"   style="height: 22px;width: 90px;" />天
                                    </td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>创建时间</th>
                                    <td><input id="createdTime" name="createdTime"  class="easyui-datetimebox"   data-options="disabled:true" style="width: 180px;" /></td>
                                </tr>
                                                                                                                                                                                                                                                                                                                                                                                                <tr>
                                    <th>编辑时间</th>
                                    <td><input id="editedTime" name="editedTime"  class="easyui-datetimebox"  data-options="disabled:true"  style="width: 180px;" /></td>
                                </tr>
                                                                                                                                <th>操作</th>
                                <td><a id="operateMode_submit" class="easyui-linkbutton" data-options="iconCls:'icon-save'">确定</a> <a id="operateMode_reset" class="easyui-linkbutton" data-options="iconCls:'icon-reload'">重置</a></td>
                                </tr>
                            </tbody>
                        </table>
                    </fieldset>
                </form>
            </div>
        </div>
        <script type="text/javascript">
            $(function() {
                var gird;
                grid=$('#grid').datagrid({
                    fit:true,
                    border : false,
                    collapsible : false,
                    rownumbers : true,
                    pagination : true,
                    singleSelect : true,
                    rownumbers : true,
                    url:ctx+'listSConstract.do',
                    columns:[[
              			{ sortable:true,field:'number',title:'表单编号'}
            		                       
            			,{ sortable:true,field:'founder',title:'发放任务人'}
            			
						,{ sortable:true,field:'contractName',title:'合同名称'}
                        
                        ,{ sortable:true,field:'contractNum',title:'合同编号'}
                                           
                        ,{ sortable:true,field:'signTime',title:'签订日期'}
                        
                        ,{ sortable:true,field:'account',title:'合同金额'}
                                           
                        ,{ sortable:true,field:'responsibleName',title:'负责人姓名'}
                                           
                        ,{ sortable:true,field:'responsiblePhone',title:'负责人电话'}
            		                       
            			,{ sortable:true,field:'customerId',title:'客户Id'}
            		                       
            			,{ sortable:true,field:'accpetType',title:'受理类型'}
            		                       
            			,{ sortable:true,field:'faultCategory',title:'错误类型'}
            		                       
            			,{ sortable:true,field:'planArriveTime',title:'计划到达时间'}
            		                       
            			,{ sortable:true,field:'planFinishTime',title:'计划结束时间'}
            		                       
            			,{ sortable:true,field:'taskType',title:'任务类型'}
            		                       
            			,{ sortable:true,field:'engineer',title:'执行人'}
            		                       
            			,{ sortable:true,field:'transportation',title:'交通方式'}
            		                       
            			,{ sortable:true,field:'contactName',title:'联系人'}
            		                       
            			,{ sortable:true,field:'contactPosition',title:'职务'}
            		                       
            			,{ sortable:true,field:'contactPhone',title:'联系人电话'}
            		                       
            			,{ sortable:true,field:'fixedPhone',title:'固定电话'}
            		                       
            			,{ sortable:true,field:'charge',title:'收费标准'}
            		                       
            			,{ sortable:true,field:'workHours',title:'标准工时'} 
            		                       
            			,{ sortable:true,field:'loopTime',title:'循环次数'}
            		                       
            			,{ sortable:true,field:'sendDemand',title:'派单要求'}
            		                       
            			,{ sortable:true,field:'issueReason',title:'故障原因'}
            		                       
            			,{ sortable:true,field:'releaseTime',title:'发布时间'}
            		                       
            			,{ sortable:true,field:'status',title:'状态信息'}
            		                       
            			,{ sortable:true,field:'loopPeriod',title:'循环周期'}
            			
            		                    ]],
                    onLoadSuccess : function(data) {
                        $('.iconImg').attr('src', fw.pixel_0);
                    },
                    onClickRow : function(index, row) {
                    	$("#form").form("reset");
                        $("#form").form("load", row);
                        $("#operateMode_title").html("修改模式");
                    }
                });
                //添加操作
                $("#btn_add").click(function() {
                    $("#operateMode_title").html("添加模式");
                    $('#grid').datagrid("unselectAll");
                    $("#id").attr("value", 0);
                    $("#form").form("reset");
                })
            
                //删除操作
                $("#btn_dele").click(function() {
                    var rows = $('#grid').datagrid('getSelections');
                    if (rows <= 0) {
                        $.messager.show({
                            title : message.title.normal,
                            msg : message.grid_select,
                            timeout : message.timeout,
                            showType : message.showType
                        });
                    } else {
                        $.messager.confirm(message.title.askTitle, message.dele_comfirm, function(r) {
                            if (r) {
                                var idValue = $("#form input[name='id']").val();
                                $.post(ctx+"delSConstract.do", {
                                    id : idValue
                                }, function(result) {
                                    if (result.success) {
                                        $.messager.show({
                                            title : message.title.normal,
                                            msg : message.dele_success,
                                            timeout : message.timeout,
                                            showType : message.showType
                                        });
                                        grid.datagrid('reload');
                                    } else {
                                        $.messager.show({
                                            title : message.title.normal,
                                            msg : message.dele_fail,
                                            timeout : message.timeout,
                                            showType : message.showType
                                        });
                                    }
                                }, 'json');
                                $("#btn_add").click();
                            }
                        });
                    }
                })
            
                 //工程师&&人员列表
		        $.getJSON(ctx+'listAllSCustomer.do',{},function(parentsJson) {
		            $("#customerId").combobox({
		    			data:parentsJson.rows,
		    			valueField:'id',
		    	         textField:'fullName',
		    	        selected:parentsJson.rows[0],
		    	        filter: function(q, row){
		            		var opts = $(this).combobox('options');
		            		return row[opts.textField].indexOf(q) == 0;
		            	}
		    	})
		        });
                
                
                //确认提交操作
                $("#operateMode_submit").click(function() {
                    var idValue = $("#form input[name='id']").val();
                    if ($('#form').form('validate')) {
                        if (idValue > 0) {
                            //修改
                            $.post(ctx+"updateSConstract.do", fw.serializeObject($('form')), function(result) {
                                if (result.success) {
                                    $.messager.show({
                                        title : message.title.normal,
                                        msg : message.update_success,
                                        timeout : message.timeout,
                                        showType : message.showType
                                    });
            
                                    grid.datagrid("reload");
            
                                    //重新获取form信息内容
                                    $("#form").form("load", ctx+"getSConstractById.do?id=" + idValue);
                                }
                            }, 'json');
                        } else {
                            if(idValue.trim().length == 0){
                                $.messager.show({
                                    title : message.title.normal,
                                    msg : message.add_button_click,
                                    timeout : message.timeout,
                                    showType : message.showType
                                });
                            }else{
                                //添加
                                $.post(ctx+"addSConstract.do", fw.serializeObject($('form')), function(result) {
                                    if (result.success) {
                                        $.messager.show({
                                            title : message.title.normal,
                                            msg : message.add_success,
                                            timeout : message.timeout,
                                            showType : message.showType
                                        });
                                        grid.datagrid("reload");
                                        $("#form").form("reset");
                                    }
                                }, 'json');
                            }
                        }
                    }
                })
                //重置操作
                $("#operateMode_reset").click(function() {
                    var idValue = $("#form input[name='id']").val();
                    if (idValue > 0) {
                        $("#form").form("load",ctx+"getSConstractById.do?id=" + idValue);
                    } else {
                        $("#form").form("reset");
                    }
                })
            });
        </script>
    </body>
</html>